import request from '../../utils/request-base'
/**
 * @description 获取验证码
 * @returns 
 */
export let getcode = (phone: number | string) => {
    return request.get(`/api/user/passport/sendCode/${phone}`)
}
interface zc {
    phone: number | string
    code: number | string
    password: number | string
}
/**
 * @description 注册账号
 * @returns 
 */
export let enroll = (data: zc) => {
    return request.post('/api/user/passport/register', data)
}
interface dl {
    phone: number | string | undefined,
    password: number | string | undefined
}
/**
 * @description 登录
 * @returns 
 */
export let login = (data: dl) => {
    return request.post('/api/user/passport/login', data)
}
/**
 * @description 获取信息
 * @returns 
 */
export let getstatus = () => {
    return request.get('/api/user/passport/auth/getUserInfo')
}
/**
 * @description 退出登录
 * @returns 
 */
export let logout = () => {
    return request.get('/api/user/passport/logout')
}
/**
 * @description 路由守卫，依次接收路由，路由器，store数据，watch 用于做路由鉴权
 * @params routep 路由
 * @params routerp 路由器
 * @params data 用户名的昵称
 * @params fn 方法 该分支内是VUE 的watch
 * @returns 
 */
export let guard = (routep: any, routerp: any, data: any, fn: any) => {
    fn(() => routep.path, () => {
        if (!data) {
            routerp.push({ path: '/u/login' })
        }
    }, { immediate: true })
}
